Skip to content

Support multiple glob patterns in sub-config matches#3516

Open
kavix wants to merge 1 commit into
facebook:mainfrom
kavix:main
Open

Support multiple glob patterns in sub-config matches#3516
kavix wants to merge 1 commit into
facebook:mainfrom
kavix:main

Conversation

@kavix
Copy link
Copy Markdown

@kavix kavix commented May 21, 2026

This change lets [[sub-config]] blocks target more than one path pattern by accepting a list of glob strings in matches. The matching logic now applies a sub-config when any pattern matches, which makes large config migrations much less repetitive.

It also keeps existing single-string configs working for compatibility, updates MyPy and Pyright migration paths to emit the new shape, and refreshes the schema, examples, and docs to reflect the new syntax.

Change SubConfig.matches from a single Glob to Vec<Glob> and add a custom serde deserializer that accepts either a single glob string or an array of glob strings for backward compatibility. Update matching logic (rewrite_with_path_to_config, matches_path) and readers/migrations to produce Vec<Glob>. Update tests, migration code, JSON schema, TOML examples and docs to reflect that `matches` can be a string or list of strings and to exercise multiple-pattern behavior.
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 21, 2026

Hi @kavix!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 21, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the cla signed label May 21, 2026
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 21, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@NathanTempest
Copy link
Copy Markdown
Contributor

Hey Kavix, thank you for signing the Meta CLA license and welcome aboard to the team! Let me review this PR and get back to you. This is a useful feature that will reduce config duplication.

Tagging @kinto0 for config ownership review.

Put up some comments on the follow-up, once these are addressed, this should be good to land!

Comment thread crates/pyrefly_config/src/config.rs
Comment thread schemas/pyrefly.json
"matches": {
"description": "A filesystem glob pattern detailing which files the config applies to.",
"type": "string"
"description": "One or more filesystem glob patterns detailing which files the config applies to.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has a lot of formatting changes unrelated to the matches field (enum values expanded to multi-line, arrays expanded, etc.). Could you regenerate using the standard tooling to minimize diff noise? The actual schema change for matches (allowing string or string[]) is correct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so do the .toml files underneath

Copy link
Copy Markdown
Contributor

@NathanTempest NathanTempest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation is solid, the serde deserializer correctly handles both string and array inputs, and the migration code properly emits arrays. I especially like that the mypy migration now consolidates multiple modules into a single sub-config with multiple globs.

Before we merge, a few things to address:

Please verify the error message formatting in crates/pyrefly_config/src/config.rs. The change from sub_config.matches (a Glob) to computing a matches string and using it in the format string looks correct, but please confirm this compiles and consider adding a test that triggers the "Extra keys found in sub config" warning to ensure the formatting works as expected.

Schema file formatting. The schemas/pyrefly.json diff includes a lot of whitespace changes unrelated to the matches field (enum values expanded to multi-line, arrays expanded, etc.). Could you regenerate this file using the project's standard schema generation tooling to avoid formatting drift? If the schema is hand-maintained, please keep the formatting consistent with the existing file.

};
Ok(SubConfig {
matches: Glob::new(self.root)?,
matches: vec![Glob::new(self.root)?],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did pyright allow both single glob and vec of glob? can we have tests for what happens in both cases?


- a `matches` key, with a [Filesystem Glob](#filesystem-globbing) detailing which files the config
applies to.
- a `matches` key, with a [Filesystem Glob](#filesystem-globbing) or list of globs detailing which
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it should be both a single glob or a list, do we have test coverage for both?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants